<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue</title>
  <script src="./js/vue.js"></script>
</head>

<body>
  <div id="app">
    <div>我是一个标题</div>
    <ul>
      <!-- 条件渲染 -->
      <li v-if="!todos">暂无数据</li>
      <template v-else>
        <li v-for="item in todos" :key="item.id">{{item.title}}</li>
      </template>
    </ul>

  </div>

  <script>

    new Vue({
      el: '#app',
      data: {
        // todos它是存在服务器端
        todos: null
      },
      // 初始化时,要到远程中去取一下数据
      async mounted() {
        let ret = await (await fetch('http://localhost:3000/api/todos')).json()
        this.todos = ret
      }


    })
  </script>
</body>

</html>